package com.rc.evcharger.common.type;


import com.rc.evcharger.common.utils.DataUtil;

import java.lang.reflect.Field;

/**
 * 写对象数据
 * @author Administrator
 */
public class ObjData extends BaseType implements DataType {
    String measuringPoint; // 测量点号
    String permisson; // 权限等级
    String password; // 密码
    String[] code;    //数据项编号
    Object[] value;   //数据项内容

    public ObjData(String measuringPoint, String permisson, String password, String[] code, Object[] value) {
        super();
        this.measuringPoint = measuringPoint;
        this.permisson = permisson;
        this.password = password;
        this.code = code;
        this.value = value;
    }

    public String getMeasuringPoint() {
        return measuringPoint;
    }

    public void setMeasuringPoint(String measuringPoint) {
        this.measuringPoint = measuringPoint;
    }

    public String getPermisson() {
        return permisson;
    }

    public void setPermisson(String permisson) {
        this.permisson = permisson;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String[] getCode() {
        return code;
    }

    public void setCode(String[] code) {
        this.code = code;
    }


    public Object[] getValue() {
        return value;
    }

    public void setValue(Object[] value) {
        this.value = value;
    }

    @Override
    public boolean customField(Field field, StringBuffer sb) {
        if (field.getName().equals("value")) {
            return true;
        }
        if (field.getName().equals("code")) {
            for (int i = 0; i < code.length; i++) {
                sb.append(code[i]).append(SPLIT)
                        .append(DataUtil.turnValue(code[i], value[i])).append(SPLIT);
            }
            return true;
        }
        return false;
    }

}
